package kr.co.handysoft.common.server;

import kr.co.handysoft.common.profiler.IServerCommandHandler;

import net.sf.json.JSONObject;

import org.apache.commons.codec.digest.DigestUtils;

public class CommunicationData {
	
	private String command;
	private String md5;
	private int length;
	private String body;
	
	public CommunicationData() {}
	
	public CommunicationData(String command) {
		this.setCommand(command);
	}
	
	public CommunicationData(String command, String body) {
		this.setBody(body);
		this.setCommand(command);
	}

	public CommunicationData(IServerCommandHandler cmdHandler) {
		this.setBody(cmdHandler.invoke());
		this.setCommand(cmdHandler.getCommand());
	}

	public String getCommand() {
		return command;
	}

	public void setCommand(String command) {
		this.command = command;
	}

	public String getMd5() {
		return md5;
	}

	public void setMd5(String md5) {
		this.md5 = md5;
	}

	public int getLength() {
		return length;
	}

	public void setLength(int length) {
		this.length = length;
	}

	public String getBody() {
		return body;
	}

	public void setBody(String body) {
		this.body = body;
		this.md5 = DigestUtils.md5Hex(body);
		this.length = this.body.length();
	}
	

	public String toJSON(){
		return JSONObject.fromObject(this).toString();
	}


}
